package com.yanyeori.framework.core.exception;

import com.yanyeori.framework.core.constant.BaseErrorCode;
import com.yanyeori.framework.core.constant.BaseWebCodeEnum;
import com.yanyeori.framework.core.util.StringUtil;

/**
 * 基础异常，提供字符串参数格式化：{}, param
 *
 * @author chenkuan 2021/1/22
 */
public class BaseException extends RuntimeException {

    private int code = BaseWebCodeEnum.SERVER_EXCEPTION.code();

    public BaseException() {
        super();
    }

    public BaseException(String message, Object... params) {
        super(StringUtil.format(message, params));
    }

    public BaseException(int code, String message, Object... params) {
        super(StringUtil.format(message, params));
        this.code = code;
    }

    public BaseException(Throwable cause, String message, Object... params) {
        super(StringUtil.format(message, params), cause);
    }

    public BaseException(BaseErrorCode baseErrorCode, Object... params) {
        super(StringUtil.format(baseErrorCode.getMsg(), params));
        this.code = baseErrorCode.getCode();
    }

    public final int getCode() {
        return code;
    }
}
